﻿using System;
using System.ComponentModel;
using System.Data.Entity;
using System.Windows.Forms;

namespace Database.Forms
{
    public partial class ParameterForm : Form
    {
        private DbSimEntities _entities;
        public ParameterForm()
        {
            InitializeComponent();
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            _entities = new DbSimEntities();
            _entities.Parameter.Load();
            parameterBindingSource.DataSource = _entities.Parameter.Local.ToBindingList();
        }

        private void parameterBindingNavigatorSaveItem_Click(object sender, EventArgs e)
        {
            try
            {
                Validate();
                _entities.SaveChanges();
                parameterDataGridView.Refresh();
            }

            catch
            {
                MessageBox.Show("Неправильный ввод");
            }
        }

        protected override void OnClosing(CancelEventArgs e)
        {
            base.OnClosing(e);
            _entities.Dispose();
        }
    }
}
